package com.chijun.mform.field.impl;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.chijun.mform.R;
import com.example.ccj.b.c.custom.tree.TreeMode;
import com.example.ccj.b.c.draw.voice.CircleRoundView;
import com.example.ccj.u.ImageUtils;
import com.example.ccj.u.StringUtils;

import java.sql.Struct;
import java.util.List;

public class AdapterForShowLianXiRen extends RecyclerView.Adapter<AdapterForShowLianXiRen.ViewHolder> {

    List<TreeMode> treeModeList;

    public AdapterForShowLianXiRen(List<TreeMode> treeModeList){
        this.treeModeList = treeModeList;

    }

    @NonNull
    @Override
    public AdapterForShowLianXiRen.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new AdapterForShowLianXiRen.ViewHolder(LayoutInflater.
                from(parent.getContext()).inflate(R.layout.adapater_for_show_lian_xi_ren, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull AdapterForShowLianXiRen.ViewHolder holder, int position) {
        TreeMode treeMode = treeModeList.get(position);
        if (StringUtils.isNoEmpty(treeMode.icon)) {
            ImageUtils.loadImage(holder.icon.getContext(),treeMode.icon,holder.icon);
        } else {
            holder.icon.setImageResource(com.example.ccj.R.mipmap.select_user_icon);
        }
        if (treeMode.name != null) holder.name.setText(treeMode.name);
    }

    @Override
    public int getItemCount() {
        return treeModeList == null ? 0 : treeModeList.size();
    }

    public static class ViewHolder extends  RecyclerView.ViewHolder{
        private final ImageView icon;
        private final TextView name;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.adapter_for_show_lian_xi_ren_name);
            icon = itemView.findViewById(R.id.adapter_for_show_lian_xi_ren_icon);

        }
    }
}
